package com.tanhua.autoconfig;


import com.tanhua.autoconfig.properties.*;
import com.tanhua.autoconfig.template.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

//定义自动装配类，里面用@Bean注解定义好了将来要纳入spring容器的bean
@EnableConfigurationProperties({  //注解使SmsProperties 生效
        SmsProperties.class,
        OssProperties.class,
        AipFaceProperties.class,
        HuanXinProperties.class,
        GreenProperties.class

})
public class TanhuaAutoConfiguration {

    @Bean
    public SmsTemplate smsTemplate(SmsProperties properties) {
        return new SmsTemplate(properties);
    }
    @Bean
    public OssTemplate ossTemplate(OssProperties properties){
        return new  OssTemplate(properties);
    }
    @Bean
    public AipFaceTemplate aipFaceTemplate(){
        return  new AipFaceTemplate();
    }
    @Bean
    public HuanXinTemplate huanXinTemplate(HuanXinProperties properties) {
        return new HuanXinTemplate(properties);
    }

    /**
     * 检测配置文件中，是否具有tanhua.green 开头的配置
     *     同时，其中的enable属性 = true
     * @param properties
     * @return
     */
    @Bean
    @ConditionalOnProperty(prefix = "tanhua.green",value = "enable", havingValue = "true")
    public AliyunGreenTemplate aliyunGreenTemplate(GreenProperties properties) {
        return new AliyunGreenTemplate(properties);
    }
}
